﻿@using System.Web.Mvc;
@using System.Web.Mvc.Html;
@using System.Web.Routing
@using VocaDb.Model.DataContracts.Artists;
@using VocaDb.Model.Domain.Artists
@using VocaDb.Model.Utils
@using VocaDb.Web.Helpers;
@using VocaDb.Model.DataContracts.Songs;
@using VocaDb.Model.DataContracts.Albums;
@using VocaDb.Model.Domain.Images;
@inherits VocaDb.Web.Code.HelperPage

@helper ArtistTypeLabel(ArtistType artistType) {
	var title = Translate.ArtistTypeName(artistType);
    switch (artistType) {
	case ArtistType.Vocaloid:
            <span class="label label-info" title="@title">V</span>
			break;

		case ArtistType.UTAU:
			<span class="label label-important" title="@title">U</span>
			break;		

		case ArtistType.CeVIO:
			<span class="label label-success" title="@title">C</span>
			break;		
				
		case ArtistType.OtherVoiceSynthesizer:
			<span class="label label-inverse" title="@title">O</span>
			break;		
					
		case ArtistType.Utaite:
			<span class="label label-info" title="@title">U</span>
			break;
			
		case ArtistType.OtherVocalist:
			<span class="label" title="@title">O</span>
			break;		
	}
}

@helper ArtistGrid(IEnumerable<ArtistContract> artists, int columns,
	bool displayType = false) {
	
	<table>
		@{ int i = 0; }
	
		@foreach (var artist in artists) {
			if (i % columns == 0) {
				@Html.Raw("<tr>")
			}
			<td>
				@ArtistIconLink(artist)
			</td>
			<td>
				@ArtistLink(artist)
				@if (displayType) {
					@("(")@Translate.ArtistTypeName(artist.ArtistType)@(")")
				}
				@if (!string.IsNullOrEmpty(artist.AdditionalNames)) {
					<br />
					<span class="extraInfo">@artist.AdditionalNames</span>
				}
			</td>
			{ i++; }
			if (i % columns == 0) {
				@Html.Raw("</tr>")
			}
		}
		@if (i % columns != 0) {
			@Html.Raw("</tr>")
		}
	</table>
			
}

@helper ArtistIconLink(ArtistContract artist) {
	<a href="@Url.Action("Details", "Artist", new { id = artist.Id })">
		<img src="@Url.ImageThumb(artist, ImageSize.TinyThumb)" alt="Thumb" class="coverPicThumb" />
	</a>		
}

@helper ArtistLink(ArtistContract artist, bool typeLabel = false, string name = null, bool releaseYear = false) {
	if (typeLabel) {
		@ArtistTypeLabel(artist.ArtistType)	 
	}
	@Html.ActionLink(name ?? artist.Name, "Details", "Artist", new RouteValueDictionary { { "id", artist.Id } }, new Dictionary<string, object> { { "title", artist.AdditionalNames }, { "data-entry-id", artist.Id }, { "class", "artistLink" }})
	if (releaseYear && artist.ReleaseDate.HasValue) {<small class="muted">&nbsp;(@artist.ReleaseDate.Value.Year)</small>}
}
	
@helper ArtistLinkList(IEnumerable<ArtistContract> artists, bool typeLabel = false, bool releaseYear = false) {
	@Html.LinkList(artists, a => new MvcHtmlString(ArtistLink(a, typeLabel, releaseYear: releaseYear).ToString()))
}

@helper ArtistList(IEnumerable<ArtistForAlbumContract> artists, bool showRoles = false, bool showType = false) {
	var ordered = artists.OrderBy(a => a.IsSupport).ToArray();
	foreach (var artist in ordered) {
		if (artist.IsSupport) {
			@("(")
		}
		if (artist.Artist != null) {
			if (showType) {
				@ArtistTypeLabel(artist.Artist.ArtistType)
			}			
			@ArtistLink(artist.Artist, name: artist.Name)
		} else {
			@artist.Name
		}
		if (showRoles && artist.EffectiveRoles != ArtistRoles.Default) {
			@Html.Raw("&nbsp;<small class='muted'>(" + Translate.ArtistRoleNames.GetAllNameNames(artist.EffectiveRoles, ArtistRoles.Default) + ")</small>")
		}
		if (artist.IsSupport) {
			@(")")
		}
		if (artist != ordered.Last()) {
			@(", ")
		}
	}
}

@helper ArtistList(IEnumerable<ArtistForSongContract> artists, bool showRoles = false, bool showType = false) {
	var ordered = artists.OrderBy(a => a.IsSupport).ToArray();
	foreach (var artist in ordered) {
		if (artist.IsSupport) {
			@("(")
		}
		if (artist.Artist != null) {
			if (showType) {
				@ArtistTypeLabel(artist.Artist.ArtistType)
			}			
			@ArtistLink(artist.Artist, name: artist.Name)
		} else {
			@artist.Name
		}
		if (showRoles && artist.EffectiveRoles != ArtistRoles.Default) {
			@Html.Raw("&nbsp;<small class='muted'>(" + Translate.ArtistRoleNames.GetAllNameNames(artist.EffectiveRoles, ArtistRoles.Default) + ")</small>")
		}
		if (artist.IsSupport) {
			@(")")
		}
		if (artist != ordered.Last()) {
			@(", ")
		}
	}
}

@helper PrintArchivedArtistData(ComparedArtistsContract comparedArtists) {

	<div class="well well-transparent archived-entry-contents">
		<h4>Content</h4>

		<table class="table table-bordered">
			@ArchivedEntryHelpers.DataRow("Id", comparedArtists.FirstData.Id)
			@ArchivedEntryHelpers.PictureRow("Main picture", comparedArtists, id => Url.Action("ArchivedVersionPicture", "Artist", new { id }))
			@ArchivedEntryHelpers.DataRow("Main picture MIME", comparedArtists, d => d.MainPictureMime)
			@ArchivedEntryHelpers.TranslatedNameRow(comparedArtists, d => d.TranslatedName)
			@ArchivedEntryHelpers.DataRowList("Names", comparedArtists, d => DataFormatUtils.GenerateHtmlFromHelper(d.Names, ArchivedEntryHelpers.NameInfo))
			@ArchivedEntryHelpers.DataRow("Description", comparedArtists, d => d.Description, preserveLineBreaks: true)
			@ArchivedEntryHelpers.DataRow("Description (en)", comparedArtists, d => d.DescriptionEng, preserveLineBreaks: true)
			@ArchivedEntryHelpers.DataRow("Release date", comparedArtists, d => d.ReleaseDate)
			@ArchivedEntryHelpers.DataRow("Artist type", comparedArtists, d => Translate.ArtistTypeName(d.ArtistType))
			@ArchivedEntryHelpers.DataRowList("External links", comparedArtists, d => DataFormatUtils.GenerateHtmlFromHelper(d.WebLinks, ArchivedEntryHelpers.WebLinkInfo))
			@ArchivedEntryHelpers.DataRow("Base voicebank", comparedArtists, d => ArchivedEntryHelpers.ObjectRefInfo(d.BaseVoicebank))
			@ArchivedEntryHelpers.DataRowList("Associated artists", comparedArtists, d => DataFormatUtils.GenerateHtml(d.Groups, g => MvcHtmlString.Create(g.NameHint + " [" + g.Id + "] (" + g.LinkType + ")")))
			@ArchivedEntryHelpers.ObjectRefList("Members", comparedArtists, d => d.Members)
			@ArchivedEntryHelpers.DataRowList("Pictures", comparedArtists, d => DataFormatUtils.GenerateHtmlFromHelper(d.Pictures, ArchivedEntryHelpers.PictureFileInfo))
		</table>

	</div>

}

@helper ArtistTypesDropdownKnockout(string binding) {
	<select data-bind="value: @(binding)">
		@foreach (var artistType in Translate.ArtistTypeNames.GetTranslatedFields(AppConfig.ArtistTypes)) {
			<option value="@artistType.Id">@artistType.Name</option>
		}
	</select>
}